﻿using System;
using System.Threading;
using Oxage.Common;

namespace Oxage.Services
{
	public class LoggingService
	{
		public static void Report(string message) //TODO: Log level
		{
			//Invoke in GUI thread
			App.ViewModel.View.Dispatcher.Invoke((CrossThreadDelegate)delegate
			{
				WriteLine(message);
			});
		}

		/// <summary>
		/// Writes a message to the log window in application.
		/// </summary>
		/// <param name="message"></param>
		public static void WriteLine(string message) //TODO: Log level
		{
			var view = App.ViewModel.View;

			//Must invoke in GUI thread
			if (view.Dispatcher.Thread != Thread.CurrentThread)
			{
				view.Dispatcher.Invoke(new Action(() =>
				{
					view.Log.WriteLine(message);
				}));
			}
			else
			{
				view.Log.WriteLine(message);
			}
		}
	}
}
